//
//  HeadImageView.m
//  mcrmSAAS
//
//  Created by wjxfhxy on 15-3-30.
//  Copyright (c) 2015年 GuangZhouXuanWu. All rights reserved.
//

#import "HeadImageView.h"

@interface HeadImageView ()
{
    __weak id<HeadImageViewDelegate> _delegate;
}
@end

@implementation HeadImageView

@synthesize delegate = _delegate;

@synthesize headImageView = _headImageView;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.userInteractionEnabled = NO;
        
        _headImageView = [[UIImageView alloc]initWithFrame:self.bounds];
        _headImageView.frame = self.bounds;
        _headImageView.layer.cornerRadius = 5;
        _headImageView.clipsToBounds = YES;
        
        [self addSubview:_headImageView];
        
        [self addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestureRecognizer:)]];
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame userInteractionEnabled:(BOOL)userInteractionEnabled
{
    self = [self initWithFrame:frame];
    
    self.userInteractionEnabled = userInteractionEnabled;
    
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    _headImageView.frame = self.bounds;
}

- (void)setHeadImage:(UIImage *)headImage
{
    _headImageView.image = headImage;
}

- (UIImage*)headImage
{
    return _headImageView.image;
}

-(void)tapGestureRecognizer:(UITapGestureRecognizer*)tapGestureRecognizer
{
    switch(tapGestureRecognizer.state)
    {
        case UIGestureRecognizerStateEnded:
        {
            [_delegate clickHeadImageView:self];
            break;
        }
        default:
            break;
    }
}

@end
